<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<!--<META HTTP-EQUIV="refresh" CONTENT="60">-->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/js/jquery-cookie.js"></script>
<script type="text/javascript" src="/js/func.js"></script>
<script type="text/javascript" src="/lang/b28n.js"></script>
<link rel="stylesheet" href="/css/dwdoor.css" type="text/css" charset="utf-8">
<link rel="stylesheet" type="text/css" href="/css/index.css">
<style type="text/css" media="screen"></style>
<style type="text/css">
    div.realtime_lock{
        float: left;
        width: 238px;
        padding-top:20px;
        padding-bottom: 18px;
        border-left: 1px solid #e3e3e3;
        border-right: 1px solid #e3e3e3;
        border-bottom: 1px solid #e3e3e3;
        position: relative;
    }
    div.bg_img_cnt{
        position: absolute;
        top:0px;
        left:0px;
        padding-top:20px;
        padding-bottom: 18px;
        width: 238px;
    }
    div.contain div.mt300{
        margin-top: 252px;
    }
    div.door_number{
        text-align: center;
    }
    div.door_number span {
      background-color: #999999;
      border-radius: 10px;
      color: #fff;
      display: inline-block;
      height: 35px;
      line-height: 35px;
      margin-top: 20px;
      width: 90px;
    }
    table.body{
        border: 1px solid #c2c2c2;
        border-collapse: collapse;
    }
    table.body, table.body th, table.body td{
        border: 1px solid #c2c2c2;
     /*   border-collapse: collapse;*/
    }
    div.contain div.noborder{
        border: 0px;
    }
    div.btn-part{
        margin-top: 20px;
    }
    div.no-pad-top{
        margin-top: 0px;
        /*padding-top: 0px;*/
    }
    div.left{
        float: left;
       /* margin: 0px;*/
    }
    div.right{
        float: right;
        /*margin: 0px;*/
    }
    div.button-container  button.btn-pre{
        margin-right:10px;
    }
    div.button-container  button.btn-next{
        margin-left:10px;
    }
    input.current{
        width:28px;
        height: 28px;
        text-align: center;
        border: 1px solid #aaa;
        margin: 0px 5px;
        vertical-align: middle;
    }
    div.hidden{
        display: none;
    }
</style>
</head>
<body onLoad="onInit()">
<div class="contain">   
<div class="sec">
<div class="title">实时开门</div>

<!-- ================= OpenDoor ================= -->
<form>
  <div class="realtime_lock" id="lock1">
      <img src="/images/lock.png" id="opendoor1" onClick='opendoor2host1();'/>
      <div class="door_number"><span>一号门进口</span></div>
      <div class="bg_img_cnt "  id="bg_img_cnt1"  style="display:none"><img src="/images/lock_click_bg.gif"><div class="door_number"><span>一号门</span></div></div>
  </div>
  <div class="realtime_lock" id="lock2">
      <img src="/images/lock.png" id="opendoor2" onClick='opendoor2host2();'>
      <div class="door_number"><span>一号门出口</span></div>
      <div class="bg_img_cnt "  id="bg_img_cnt2"  style="display:none"><img src="/images/lock_click_bg.gif"><div class="door_number"><span>二号门</span></div></div>
  </div>
  <div class="realtime_lock" id="lock3">
    <img src="/images/lock.png" id="opendoor3" onClick='opendoor2host3();'>
    <div class="door_number"><span>二号门进口</span></div>
    <div class="bg_img_cnt "  id="bg_img_cnt3"  style="display:none"><img src="/images/lock_click_bg.gif"><div class="door_number"><span>三号门</span></div></div>
</div>
  <div class="realtime_lock" id="lock4">
    <img src="/images/lock.png" id="opendoor4" onClick='opendoor2host4();'>
    <div class="door_number"><span>二号门出口</span></div>
     <div class="bg_img_cnt "  id="bg_img_cnt4"  style="display:none"><img src="/images/lock_click_bg.gif"><div class="door_number"><span>四号门</span></div></div>
</div>
</form>	
</div>
<div class="sec mt300 noborder" style="margin-top:245px">
 <form method="post" id="outputExcelall" action="/cgi-bin/downlaodExcel.sh" enctype="multipart/form-data">
      <table class="body" width="95%" border="1" cellpadding="2" cellspacing="1" id="staff_table2">
        <tr id="s0" align="center">
		  
           <th class="title" width="8%" id="s0_0">序号</th>
           <th class="title" width="20%" id="s0_1">卡号</th>
           <th class="title" width="20%" id="s0_2">门号</th>
		   <th class="title" width="12%" id="s0_3">通行</th>
           <th class="title" width="35%" id="s0_4">刷卡时间</th>
        </tr>
    </table>	 
</form> 
            <div class="btn-part no-pad-top" style="margin-top:2px;">       
                <div class="button-container left" style="padding-top:0px;">                    
                    <button id="mandbImport" class="button-button button-button-auto btn-export-all" download="download.csv" onclick='return outputpreconfirm();'><span class="text button-text">导出全部文件</span></button>
                </div>
                <div class="button-container right"  style="padding-top:0px;">
                <button id="pagebnpre" class="button-button btn-pre" type="button"   value="上一页" onclick='setpagebnpre();'>上一页 </button>                   
                第<input id="pagebn" type="text" class="current"  value=""/>页&nbsp;   
                <button id="pagebnnxt" class="button-button btn-next" type="button"  value="上一页" onclick='setpagebnnxt();'>下一页 </button>                            
                </div>
            </div>

</div>
</div>
</body>
<script type="text/javascript">  
Butterlate.setTextDomain("dwdoor");
var gatetab = <%dwGateGet();%>;
var openArr = [0,0,0,0];
function getopenArr()
{ 
    var nrows = 4;   
    if(gatetab.nrows!="") nrows=gatetab.nrows;
    for(var l=1;l<=nrows;l++)
    {   
        openArr[(l-1)] = parseInt(gatetab['s'+l+'_4'],10)*1000+parseInt(gatetab['s'+l+'_5'],10)*1000;
//		alert("openArr["+(l-1)+"]:"+ openArr[(l-1)]+"gatetab:"+gatetab['s'+l+'_5']);
    }	
}	
function alertContents1()
{
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
//		    alert("openArr[0]:"+openArr[0]);
            setTimeout(function(){
			   $("#opendoor1").show();
			   $("#bg_img_cnt1").hide();
			},openArr[0]);           
        } else {
//            alert('There was a problem with the request.');
        }
    }
}
function alertContents2()
{
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
//		    alert("openArr[1]:"+openArr[1]);
		    setTimeout(function(){
                $("#opendoor2").show();
			    $("#bg_img_cnt2").hide();
			},openArr[1]);
        } else {
//            alert('There was a problem with the request.');
        }
    }
}
function alertContents3()
{
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
//		    alert("openArr[2]:"+openArr[2]);
		    setTimeout(function(){
                $("#opendoor3").show();
			    $("#bg_img_cnt3").hide();
			},openArr[2]);
        } else {
//            alert('There was a problem with the request.');
        }
    }
}
function alertContents4()
{
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
//		    alert("openArr[3]:"+openArr[3]);
		    setTimeout(function(){ 
                $("#opendoor4").show();
			    $("#bg_img_cnt4").hide();
			},openArr[3]);
        } else {
//            alert('There was a problem with the request.');
        }
    }
}
function makeRequest(url, content) 
{
    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
	if(content == 'opendoor1')
	{
        http_request.onreadystatechange = alertContents1;
	}else if(content == 'opendoor2')
	{
        http_request.onreadystatechange = alertContents2;
	}else if(content == 'opendoor3')
	{
        http_request.onreadystatechange = alertContents3;
	}else if(content == 'opendoor4')
	{
        http_request.onreadystatechange = alertContents4;
	}
    http_request.open('POST', url, true);
    http_request.send(content);
}

function opendoor2host1()
{
    $("#opendoor1").hide();
	$("#bg_img_cnt1").show();
    makeRequest('/goform/opendoor1',"opendoor1");
}
function opendoor2host2()
    {   
    $("#opendoor2").hide();
	$("#bg_img_cnt2").show();
    makeRequest('/goform/opendoor2',"opendoor2");
    }
function opendoor2host3()
{
    $("#opendoor3").hide();
	$("#bg_img_cnt3").show();
    makeRequest('/goform/opendoor3',"opendoor3");
}
function opendoor2host4()
{
    $("#opendoor4").hide();
	$("#bg_img_cnt4").show();
    makeRequest('/goform/opendoor4',"opendoor4");
	}
//tab setup
var pagei=1;
var pagemax=1;
function setTab(data)
{ 
    var table2 = document.getElementById('staff_table2');
    var rowslen = table2.rows.length;  	
    for(var j=rowslen-1;j>=1;j--)
	{
	    table2.deleteRow(j);
	}
//    alert("rowslen:"+rowslen);	
	$.ajax
    ({
        url: "/goform/dwreadaccess",
        type: "POST",
        timeout: 180000,
        data: data,
        dataType: "text",

        error: function()
        {
            alert('网络错误。'); 
            return false;
        },
        complete: function()
        {              
            if (status === 'timeout')
            {
                alert('超时。');
                this.abort();
            }
        },
        success: function(deReturn)
        {
 //   		alert(deReturn);
            var accesstab = jQuery.parseJSON(deReturn);	
//		alert(accesstab);
			var nrows=accesstab.nrows;
			var ncols=accesstab.ncols;
			pagemax=accesstab.pagemax;
	//		alert("pagemax:"+pagemax);
			var accesspagenum=accesstab.accesspagenum;
			pagei=parseInt(accesspagenum);
	//		alert("pagei:"+pagei);
			for(var l=1;l<=nrows;l++)
			{		    
				inrow=table2.insertRow(l);			
				inrow.setAttribute("id","s" + l);
				inrow.setAttribute("align","center");
				for(var m=0;m<ncols;m++)
				{
					var incell = inrow.insertCell(m);
					if(m==2)
					{
						if(accesstab['s'+l+'_'+m]=='0') incell.innerHTML = '<td><class="head2" id="s'+l+'_'+m+'">'+'一号门进口'+'</td>';
						if(accesstab['s'+l+'_'+m]=='1') incell.innerHTML = '<td><class="head2" id="s'+l+'_'+m+'">'+'一号门出口'+'</td>';
						if(accesstab['s'+l+'_'+m]=='2') incell.innerHTML = '<td><class="head2" id="s'+l+'_'+m+'">'+'二号门进口'+'</td>';
						if(accesstab['s'+l+'_'+m]=='3') incell.innerHTML = '<td><class="head2" id="s'+l+'_'+m+'">'+'二号门出口'+'</td>';
					}else if(m==3)
					{
	//					if(accesstab['s'+l+'_'+m]!='access') incell.innerHTML = '<td><class="head2" id="s'+l+'_'+m+'">'+'拒绝'+'</td>';
						if(accesstab['s'+l+'_'+m]=='pass')
						{
							incell.innerHTML = '<td><class="head2" id="s'+l+'_'+m+'">'+'通过'+'</td>';
						}else
						{
							incell.innerHTML = '<td><class="head2" id="s'+l+'_'+m+'">'+'拒绝'+'</td>';
						}
					}else
					{
						incell.innerHTML = '<td><class="head2" id="s'+l+'_'+m+'">'+accesstab['s'+l+'_'+m]+'</td>';			    
					}			
				}
			}
			var bn=document.getElementById("pagebn");
			//bn.value="第"+pagei+"页"; 	
			if(isNaN(pagei))	
			{
				pagei = 1;
			}
			bn.value=pagei;
		}           
    });	
}

function setpagebnpre()
{
    if(pagei==1)
	{
        alert("当前已经是第一页!");
	}else
	{
	    pagei -= 1;
		var data="{\"yeshu\":\""+pagei+"\"}";
        setTab(data);
//        makeRequest("/goform/dwsetaccesspage",pagei.toString());       
//        setTimeout(function()
//		{
//            window.location.href="/door/doorcontrol.asp";
//		},500);
	}
}

function setpagebnnxt()
{
    if(pagei==pagemax)
	{
		alert("当前已经是最后一页!");
	}else
	{
	    pagei += 1;
		var data="{\"yeshu\":\""+pagei+"\"}";
        setTab(data);
//        makeRequest("/goform/dwsetaccesspage",pagei.toString());     
//        setTimeout(function()
//		{
//            window.location.href="/door/doorcontrol.asp";
//		},500);
	}
}

function outputpreconfirm()
{
    var r = confirm("温馨提示：导出的文件中含有中文时，请用新的EXCEL表选择：数据->来自文本->带逗号的格式 导入打开。");    
	if (r==true)
                {
    	document.getElementById("outputExcelall").submit();
            }			
  	else
    {
    	return false;
	}
}  

function initTranslation()
{
	var e = document.getElementById("Gate Config");
	e.innerHTML = _("Gate Config");
	e = document.getElementById("GateIntroduction");
	e.innerHTML = _("GateIntroduction");
}

function onInit()
{
    var data = "{\"yeshu\":\"1\"}";
    setTab(data);
	getopenArr();
}

$("#pagebn").bind("keypress", function(event)
{
    // console.log(event);
    if(event.keyCode == "13")
    {
        var num =  parseInt($("#pagebn").val());
        if(isNaN(num))
        {
            alert("非法的页数");
            return false;
        }
        if((num <= 0) || (num > pagemax))
        {
            alert("非法的页数");
            return false;
        }
        // console.log(num);
		var data="{\"yeshu\":\""+num+"\"}";
        setTab(data);
//        makeRequest("/goform/dwsetaccesspage",num.toString());     
//        window.location.reload();
    }
})

$(function()
{
        if($.cookie('logon') === "null" || !$.cookie('logon'))
		{
            top.window.location.pathname = '/login.asp';
        }
        
//        $(top.window).mousemove(function(){
//        checkCookie();
//    });
    function checkCookie()
	{
        var a = $.cookie('logon') === "null" || !$.cookie('logon');
        if(a)
		{
            top.window.location.pathname = '/login.asp';
        }else
		{
            var date = new Date();
            date.setTime(date.getTime() + (60 * 60 * 1000));
            $.cookie('logon',true,{expires: date});      
        }
    }
});

</script>
</html>
